﻿using UnityEngine;

public class CameraDrag : MonoBehaviour {
	// === Unity ======================================================================================================
	private void Awake() {
		_transform = transform;
		_camera = gameObject.camera;
	}

	private void Update() {
		if (!Input.GetMouseButton(InputConstants.MOUSE_BUTTON_RIGHT)) {
			return;
		}
		if (Input.GetMouseButtonDown(InputConstants.MOUSE_BUTTON_RIGHT)) {
			_dragOrigin = Input.mousePosition;
			_posOrigin = _transform.position;
		}
		var pos = _camera.ScreenToWorldPoint(Input.mousePosition) - _camera.ScreenToWorldPoint(_dragOrigin);
		_transform.position = _posOrigin - pos;
	}

	// === Private ====================================================================================================
	private Transform _transform;
	private Camera _camera;
	private Vector3 _dragOrigin;
	private Vector3 _posOrigin;
}